﻿using System;
using System.Windows;
using Creventive.Wpf.ShellFactory.Workspace;

namespace MultiViewWithLogin.Shell.Login
{
    /// <summary>
    ///   Interaction logic for LoginView.xaml
    /// </summary>
    internal partial class LoginView : ApplicationView<ILoginViewModel>
    {
        public LoginView()
        {
            this.InitializeComponent();
        }

        private void LoginView_ViewModelLoaded(object sender, EventArgs e)
        {
            this.ViewModel.Succeeded += this.ViewModel_Succeeded;
        }

        private void ViewModel_Succeeded(object sender, EventArgs e)
        {
            WindowWorkspace.Close(this, true);
        }

        private void cancelButton_Click(object sender, RoutedEventArgs e)
        {
            WindowWorkspace.Close(this, false);
        }

        private void okButton_Click(object sender, RoutedEventArgs e)
        {
            /*
                The passwordbox is a real pain to work with when it comes to binding, so we'll have to do some manual work. 
                That is why I am using events and not commands in this case.
            */
            string[] parameter = new[] { this.userNameBox.Text, this.passwordBox.Password };
            this.ViewModel.LoginCommand.Execute(parameter);
        }
    }
}